package cn.skycity.framework.service.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal;
import org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector;

/**
 * 自定义验证令牌
 * @Author liguang8
 * @Date 2023-08-18
 * @Version 1.0
 */
@Slf4j
@Configuration
public class CustomOpaqueTokenIntrospector implements OpaqueTokenIntrospector {

//    @Resource
//    private OAuth2AuthorizationService authorizationService;

    @Override
    public OAuth2AuthenticatedPrincipal introspect(String token) {
//        OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
//        if (Objects.isNull(authorization)) {
//            throw new InvalidBearerTokenException(token);
//        }

//        CustomUserDetails userDetails = null;
//        try {
//            UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = authorization.getAttribute(Principal.class.getName());
//            userDetails = (CustomUserDetails) Objects.requireNonNull(usernamePasswordAuthenticationToken).getPrincipal();
//        }
//        catch (UsernameNotFoundException notFoundException) {
//            log.warn("用户不不存在 {}", notFoundException.getLocalizedMessage());
//            throw notFoundException;
//        }
//        catch (Exception ex) {
//            log.error("资源服务器 introspect Token error {}", ex.getLocalizedMessage());
//        }
        return null;
    }
}
